package com.palnar.ilecker.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.ksoap2.serialization.SoapObject;

public class ItemGroup extends GroupGeneric<MenuItem> implements Serializable {
	
	private int clientId;
	private int serverId;	
	private List<MenuItem> items;
	private byte[] image;	
	
	public ItemGroup() {
		items= new ArrayList<MenuItem>();
			}

	public int getClientId() {		
		return this.clientId;
	}
	
	public int getServerId() {		
		return this.serverId;
	}
	
//	public String getName() {		
//		return this.name;
//	}

	public byte[] getImage() 
	{
		return image;
	}
	
	
	public void setClientId(int id) {
		this.clientId= id;		
	}

	public void setServerId(int id) {
		this.serverId= id;		
	}

//	public void setName(String name) {
//		this.name=name;		
//	}	

	public void setImage(byte[] image)
	{
		this.image=image;
	}

	@Override
	public Iterator<MenuItem> iterator() {		
		return null;
	}

	public List<MenuItem> GetItemsCollection() {		
		return this.items;
	}
	
	public void SetItemsCollection(List<MenuItem> items) {		
		 this.items=items;
	}
	
	public void addMenuItem(MenuItem item)
	{
	 this.items.add(item);
	}
	
	public MenuItem TryGetItem(Integer id)
	{		
		if(!this.items.isEmpty())
		{
			for (MenuItem item : this.items) 
			{
				if(item.getClientId()== id)
				{
				 return item; 
				}
			}
		}
		return null;
	}

	public static ItemGroup ItemGroupBuilder(SoapObject outputSoapObject, HashMap<Integer, Language> languages) 
	{
		ItemGroup itemGroup = new ItemGroup();
		List<MenuItem > menuItemList = new ArrayList<MenuItem>();
	    itemGroup.serverId = Integer.parseInt(outputSoapObject.getProperty("Id").toString());
	    itemGroup.setName(Integer.parseInt(outputSoapObject.getProperty("Name").toString()));
		SoapObject itemGroupSoapObject = (SoapObject) outputSoapObject.getProperty("Children");
		
		for(int i = 0; i < itemGroupSoapObject.getPropertyCount(); i++)
  		{
			MenuItem menuItem = new MenuItem();
 		    menuItem = MenuItem.MenuItemGroupBuilder((SoapObject)itemGroupSoapObject.getProperty(i),languages);
		    menuItemList.add(menuItem);
  		}
	    itemGroup.items = menuItemList;	    
		
		return itemGroup;
	}
	
	public ItemGroup UpdateAvailabilityBuilder(SoapObject outputSoapObject)
	{
		for (MenuItem item : GetItemsCollection()) {
			
		}
		return null;
	}
}
